<?php
namespace BoxEdu\Controller\Admin;
//use Think\Controller;
class AgentApplyController extends CommonController {
	public function _initialize() {
		parent::_initialize();
		$this->status_array = array(
			'1' => '待审核',
			'2' => '审核通过',
			'3' => '审核不通过',

		);
	}

	/******代理申请记录****/
	public function index() {
		$where = "1";
		if ($this->kw = I('kw')) {
			$where .= " and (moreFields like '%$this->kw%' or phone like '%$this->kw%' or name like '%$this->kw%')";
		}
		$data = BoxModel('edu_user_agent_apply')->get($where, 20, "id desc");
		$this->data = $data['list'];
		// dump($data);
		$this->show_page($data['pager']);
		$this->display();
	}

	/******通过****/
	public function status() {
		$id = I('id');
		$data = BoxModel("edu_user_agent_apply")->load($id);
		$data['content'] = json_decode($data['content'], true);
		$user_info = BoxModel("edu_user")->where(array('user_id' => $data['user_id']))->find();
		$agent_frozen_capital = intval(dict('agent_frozen_capital'));
		if ($user_info['is_agent'] == 1) {
			$agent_frozen_capital = $user_info['frozen_capital'];
		}
		$this->agent_frozen_capital = I('agent_frozen_capital', $agent_frozen_capital, "intval");
		$this->data = $data;
		if (IS_POST) {
			$is_show = I('status');
			if (I('expirationTime')) {
				$expirationTime = strtotime(I('expirationTime'));
			}

			$r = BoxModel('edu_user_agent_apply')->save(array('id' => $id, 'status' => $is_show, 'remark' => I('remark'), 'expirationTime' => $expirationTime));
			/*******通过**/
			if ($is_show == 2) {
				// $agent_num = createCardNo($this->data['user_id']);
				Logic("BoxEdu", "User")->beAgent($this->data['user_id'], $this->agent_frozen_capital);

			}

			$this->jump("操作成功");
		}
		$this->display();
	}

}